package com.woniu.service.Impl.backpage;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.dao.backpage.DepotDao;
import com.woniu.entity.Depot;
import com.woniu.service.backpage.IDepotService;
import com.woniu.util.RequestParams;
import com.woniu.util.ResData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 仓库表实现层
 * @author 任楷锐
 * @data 2023/3/9 14:47
 */
@Service
public class DepotServiceImpl implements IDepotService {
    @Autowired
    private DepotDao depotDao;

    //查询所有仓库信息
    @Override
    public ResData<?> getAllDepot(RequestParams<Depot> requestParams) {
        //实现分页
        PageHelper.startPage(requestParams.getPageNo(),requestParams.getPageSize());
        List<Depot> allDepot = depotDao.findAllDepot(requestParams.getData().getMultiple(),requestParams.getData().getRegion(), requestParams.getData().getMinArea(),requestParams.getData().getMaxArea());
        PageInfo<Depot> pageInfo = new PageInfo<Depot>(allDepot);
        return new ResData<>().ok(pageInfo);
    }

    //根据id查询一条仓库的信息
    @Override
    public ResData<?> getDepotById(Integer id) {
        Depot depotById = depotDao.findDepotById(id);
        return new ResData<>().ok(depotById);
    }

    //新增仓库
    @Override
    public ResData<?> insertDepot(Depot depot) {
        depotDao.addDepot(depot);
        return new ResData<>().ok();
    }

    //查询所有区域信息
    @Override
    public ResData<?> getAllRegion() {
        List<Depot> allRegion = depotDao.findAllRegion();
        return new ResData<>().ok(allRegion);
    }


    //查询所有仓库名称
    @Override
    public ResData<?> getAllDepotName() {
        List<Depot> allDepotName = depotDao.findAllDepotName();
        return new ResData<>().ok(allDepotName);
    }
}
